package com.uab.ia.entidades;

import com.android.dataframework.Entity;

public class Conexion {

	private long id;
	private long id_e1;
	private long id_e2;
	private int time;
	private boolean conected;
	private final static String table = "conexion";
	private String linea;

	public Conexion() {

	}

	public Conexion(Entity ent) {
		try {
			this.id = ent.getId();
			this.id_e1 = ent.getLong("id_e1");
			this.id_e2 = ent.getLong("id_e2");
			this.time = ent.getInt("tiempo");
			this.linea = ent.getString("linea");
			this.conected = Boolean.parseBoolean(ent.getString("con"));
		} catch (Exception e) {

		}
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public long getId_e1() {
		return id_e1;
	}

	public void setId_e1(long id_e1) {
		this.id_e1 = id_e1;
	}

	public long getId_e2() {
		return id_e2;
	}

	public void setId_e2(long id_ed2) {
		this.id_e2 = id_ed2;
	}

	public int getTime() {
		return time;
	}

	public void setTime(int time) {
		this.time = time;
	}

	public boolean isConected() {
		// Estacion e1 = new Estacion(id_e1);
		// Estacion e2 = new Estacion(id_e2);

		// return e1.linea.equals(e2.linea);
		return conected;
	}

	public void setConected(boolean conected) {
		this.conected = conected;
	}

	public void save() {
		Entity ent;
		if (this.id != -1) {
			ent = new Entity(table, this.id);
		} else {
			ent = new Entity(table);
		}

		ent.setValue("id_e1", this.id_e1);
		ent.setValue("id_e2", this.id_e2);
		ent.setValue("tiempo", this.time);
		ent.setValue(table, this.conected);
		ent.save();
	}

	@Override
	public String toString() {
		return "Estacion 1: " + Long.toString(this.id_e1) + "\n"
				+ "Estacion 2: " + Long.toString(this.id_e2) + "\n"
				+ "Tiempo: " + Integer.toString(this.time);
	}

	public String getLinea() {
		return linea;
	}

	public void setLinea(String linea) {
		this.linea = linea;
	}
}
